<?php namespace web\home\controller;
/** .-------------------------------------------------------------------
 * |  Software: [HDPHP framework]
 * |      Site: www.hdphp.com
 * |-------------------------------------------------------------------
 * |    Author: 向军 <2300071698@qq.com>
 * |    WeChat: aihoudun
 * | Copyright (c) 2012-2019, www.houdunwang.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

class User extends Common {
	private $db;
	public function __construct(){
		parent::__construct();
		$this->db=new \system\model\User;
		
	}
	
//	会员中心
	public function user(){
		View::with('title','会员中心');
//		if(!$_SESSION['name']){
//			message('请填写用户昵称',U('home/user/info'));
//		}
//		会员数据
		$uData=$this->db->where('uid',$_SESSION['id'])->first();
//		p($uData);die;
		View::with('uData',$uData);
//		获取订单数据
		$data=Db::table('orderlist')->join('goods_list','orderlist.glid','=','goods_list.glid')
			->join('goods','orderlist.gid','=','goods.gid')
			->join('orders','orderlist.oid','=','orders.oid')
			->where('orders.uid',$_SESSION['id'])->get();
//			
			foreach ($data as $key => $value) {
				$data[$key]['combine']=explode('|',$value['combine']);
				foreach($data[$key]['combine'] as $k=>$v){
					$data[$key]['combine'][$k]=Db::table('goods_attr')->join('type_attr','goods_attr.taid','=','type_attr.taid')->where('gtid',$v)->lists('taname,gtvalue');
				}
//				$data[$key]['combine']=implode('|',$data[$key]['combine']);
			}
//			p($data);die;
		View::with('data',$data);
		
//		获取订单状态数据
//		待付款
		$oldData1=count(Db::table('orders')->where('uid',$_SESSION['id'])->where('status','待付款')->get());
//		待发货
		$oldData2=count(Db::table('orders')->where('uid',$_SESSION['id'])->where('status','待发货')->get());
		
		
		View::with('oldData',array('o1'=>$oldData1,'o2'=>$oldData2));
//		p($oldData);die;
		
		View::make();
	}
	
	
//	验证码
	public function code(){
		
//		验证码宽高
		Code::width(110)->height(40)->make();
//		验证码字体大小颜色
		Code::fontSize(20)->fontColor('#f00f00')->make();
//		验证码背景颜色
		Code::background('#999999')->make();
//		设置验证码数量
		Code::num(4)->make();
//		验证码字体
		Code::font('public/font.ttf')->make();
//		显示验证码
		Code::make();
	}
//	密码修改
	public function word(){
		if(IS_POST){
			$re=$this->db->wordEdit();
			if(!$re){
				message('密码修改失败',U('word'));
			}
			message('密码修改成功',U('word'));
		}
		
		View::make();
	}
	
//	个人资料
	public function info(){
		View::with('title','个人资料');
		
		if(IS_POST){
			$this->db->infoEdit();
		}
		
		$data=$this->db->where('uid',$_SESSION['id'])->first();
//		p($data);die;
		$data['address']=explode('|',$data['address']);
		View::with('data',$data);
		View::make();
	}
	
//	收货地址
	public function dizhi(){
		$data=Db::table('user')->where('uid',$_SESSION['id'])->first();
		$data['address']=explode(',',$data['address']);
//		p($data);die;
		View::with('data',$data);
		View::make();
	}
	
	
	
	
	
	
	
	
	
	
	
}